package com.hliushi.redis.service;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author llhuang10
 * @date 2021/8/7 20:14
 */
@Service
public class IdGenerator {

    public static final String ID_KEY = "id:generator:cart";
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 生成全局唯一Id
     *
     * @return long
     */
    public Long incrementId() {
        return stringRedisTemplate.opsForValue().increment(ID_KEY);
    }
}
